package org.openbpm.bus.model;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;

import java.io.Serializable;
import java.util.Date;

@lombok.Data
@TableName("bus_data_log")
public class BusinessDataLog implements Serializable {

    @TableId
    private Long id;
    @TableField("log_type")
    private String logType;
    @TableField("bus_id")
    private String busPk;
    @TableField("form_key")
    private String formKey;
    @TableField("bo_key")
    private String boKey;
    @TableField(value = "change_data",typeHandler = FastjsonTypeHandler.class)
    private JSONArray changeData;
    //主表字段： 字段key，字段描述，原值，新值
    //一对一字段字段同主表字段
    //一对多子表：子表key，子表描述，id 增， id 删， id 改
    @TableField("change_log")
    private String changeLog;
    @TableField("user_account")
    private String userAccount;
    private String postuid;
    private Date postdate;
    @TableField(value = "form_data",typeHandler = FastjsonTypeHandler.class)
    private JSONObject formData;

    public void addChangeItem(String busPk, JSONObject changeItem){
        if(this.busPk==null){
            this.busPk = busPk;
        }
        if(changeData==null){
            changeData = new JSONArray();
        }
        changeData.add(changeItem);
    }
}
